<!doctype html>
<html lang="zh-CN" th:replace="admin-layout :: layout(~{::title}, ~{}, ~{::script}, ~{::body}, 'exam-list')"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>考试列表</title>
    <script>
        var $table = $("#table");
        var $remove = $("#removeBtn");
        var $update = $("#updateBtn");
        var $info = $("#infoBtn");
        var $paper = $("#paperBtn");
        var $user = $("#userBtn");
        var $search = $("#searchBtn");
        var $dataBtn = $("#dataBtn");
        var $manageBtn = $("#manageBtn");
        var $markingBtn = $("#markingBtn");
        var selections = []

        //$(this).serialize()
        $(function () {
            tableList(columns)
        })

        var columns = [{
            checkbox: true
        }, {
            field: 'name',
            title: '考试名称',
        }, {
            field: 'startTime',
            title: '开始时间',
        }, {
            field: 'endTime',
            title: '结束时间',
        }, {
            field: 'paperNum',
            title: '试卷数量',
        }, {
            field: 'userNum',
            title: '用户数量',
        }]

        $remove.click(function () {
            confirmAlert(function () {
                var ids = getIdSelections();
                ajaxJson("/admin/exam/ajax/delete", {"ids": ids.toString()}, function (res) {
                    if (res.status) {
                        $table.bootstrapTable('remove', {
                            field: 'id',
                            values: ids
                        })
                        $remove.prop('disabled', true);
                        $update.prop('disabled', true);
                        $info.prop('disabled', true)
                        $paper.prop('disabled', true)
                        $user.prop('disabled', true)
                        $manageBtn.prop('disabled', true)
                        $dataBtn.prop('disabled', true)
                        $markingBtn.prop('disabled', true)
                    }
                })
            })
        })

        $update.click(function () {
            var ids = getIdSelections()
            if (ids){
                location.href = "/admin/exam/save?id=" + ids[0]
            }
        })

        $info.click(function () {
            var ids = getIdSelections()
            if (ids){
                location.href = "/admin/exam/info/" + ids[0]
            }
        })

        $user.click(function () {
            var ids = getIdSelections()
            if (ids){
                location.href = "/admin/exam/user/" + ids[0]
            }
        })

        $paper.click(function () {
            var ids = getIdSelections()
            if (ids){
                location.href = "/admin/exam/paper/" + ids[0]
            }
        })

        function getIdSelections() {
            return $.map($table.bootstrapTable('getSelections'), function (row) {
                return row.id
            })
        }

        $manageBtn.on("click",function(){
            var ids = getIdSelections()
            if (ids){
                location.href='/admin/exam/manage/' + ids[0]
            }
        })

        $dataBtn.click(function(){
            location.href='/admin/exam/data/' + selections[0];
        })

        $markingBtn.click(function(){
            location.href='/admin/exam/marking/' + selections[0];
        })

        $table.on('check.bs.table uncheck.bs.table ' +
            'check-all.bs.table uncheck-all.bs.table',
            function () {
                $remove.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $update.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $info.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $paper.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $user.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $manageBtn.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $dataBtn.prop('disabled', !$table.bootstrapTable('getSelections').length)
                $markingBtn.prop('disabled', !$table.bootstrapTable('getSelections').length)

                // save your data, here just save the current page
                selections = getIdSelections()
                // push or splice the selections if you want to save all data selections
            })

        $search.click(function () {
            $table.bootstrapTable('refresh')
        })
    </script>
</head>
<body>
<!--<ol class="breadcrumb">
    <li class="active">考试列表</li>
</ol>-->
<div class="">
    <form id="toolbar">
        <input type="hidden" name="page" id="page">
        <div class="row">
            <div class="col-sm-4 col-md-4 col-lg-3">
                <input type="text" class="form-control input-clear" name="name"
                       placeholder="考试名称"
                       autocomplete="off">
            </div>
            <div class="col-sm-4 col-md-4 col-lg-3">
                <a href="javascript:void(0)" class="btn btn-primary" id="searchBtn">查询</a>
                <a href="javascript:void(0)" class="btn btn-warning" id="clearSearchBtn">清空</a>
            </div>
        </div>
    </form>
</div>
<hr>
<div class="fyl-mb20">
    <a th:href="@{/admin/exam/save}" class="btn btn-primary">添加</a>
    <button class="btn btn-primary" id="manageBtn" disabled>管理</button>
    <button class="btn btn-primary" id="dataBtn" disabled>数据</button>
    <button class="btn btn-primary" id="markingBtn" disabled>阅卷</button>
<!--    <button type="button" class="btn btn-primary" id="paperBtn" disabled>试卷</button>-->
<!--    <button type="button" class="btn btn-primary" id="userBtn" disabled>用户</button>-->
    <button type="button" class="btn btn-primary" id="updateBtn" disabled>修改</button>
    <button type="button" class="btn btn-danger" id="removeBtn" disabled>删除</button>
</div>
<table id="table" data-url="/admin/exam/ajax/list"></table>
</body>
</html>